<script>
  /**
   * Definition for singly-linked list.
   * function ListNode(val) {
   *     this.val = val;
   *     this.next = null;
   * }
   */

  /**
   * @param {ListNode} headA
   * @param {ListNode} headB
   * @return {ListNode}
   */

  // https://leetcode.cn/problems/intersection-of-two-linked-lists/description/?envType=study-plan-v2&envId=top-100-liked
  var getIntersectionNode = function (headA, headB) {
    if (headA === null || headB === null) return null;
    let pA = headA,
      pB = headB;
    while (pA !== pB) {
      pA = pA === null ? headB : pA.next;
      pB = pB === null ? headA : pB.next;
    }
    return pA;
  };
</script>
